<?php 
include "../public/header.php";
//引入数据库文件
include "../public/common.php";

if($_POST['tel'] || $_GET['tel']) {
	$user_tel = ($_POST['tel'] != null)?$_POST['tel']:$_GET['tel'];
	//查询会员信息
	$sql = "select user_name,user_tel,card_integral from card,user where user_tel='{$user_tel}' and card.card_id = user.card_id";
	if($result = $conn->query($sql)) {
		if($result != null && $row = $result->fetch_assoc()) {
			$sql = "select card_id from card where card_integral = {$row['card_integral']}";
			if($res = $conn->query($sql)) {
				$row1 = $res->fetch_assoc();
			}
?>

<!-- 右侧内容块 -->
<div class="col-md-9">
	<div class="panel panel-default">
	  <div class="panel-heading">
	    <span class="label label-primary">会员名：<b><?php echo $row['user_name'] ?></b></span>
	    <span class="label label-success">会员手机号：<b><?php echo $row['user_tel'] ?></b></span>

	  </div>
	  <div class="panel-body">
	  	<button href="javascript:" class="btn btn-primary">
		  总积分 <span class="badge"><?php echo $row['card_integral'] ?></span>
		</button>
	  	<hr>
		    <!-- 扣除积分部分 -->
			<button type="button" class="btn btn-danger btn-lg" data-toggle="modal" data-target="#myModal">
			  扣积分
			</button>

			<!-- Modal -->
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			  <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">扣除积分</h4>
			      </div>
			      <div class="modal-body">
			        <form action="reduce.php" method="post">
			        	<div class="form-group">
			        		<label>扣除积分数</label>
			        		<input type="text" name='integral' class="form-control" placeholder="请输入将要扣除的积分数" />
			        	</div>
			        	<div class="form-group">
			        		<label>积分扣除事由</label>
			        		<input type="text" name="reason" class="form-control" placeholder="请输入将要扣除积分的原因" />
			        	</div>
			        	<input type="hidden" name="id" value="<?php echo $row1['card_id']; ?>">
			        	<input type="hidden" name="tel" value="<?php echo $user_tel; ?>">
			        	<div class="form-group">
			        		<input type="reset" class="btn btn-primary" />
			        		<input type="submit" class="btn btn-danger" />
			        	</div>
			        </form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			      </div>
			    </div>
			  </div>
			</div>
			<!-- 扣除积分部分结束 -->
			<!-- 增加积分部分 -->
			<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal1">
			  增加积分
			</button>
			<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			  <div class="modal-dialog" role="document">
			    <div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">增加积分</h4>
			      </div>
			      <div class="modal-body">
			        <form action="addIntegral.php" method="post">
			        	<div class="form-group">
			        		<label>增加积分数</label>
			        		<input type="text" name="integral" class="form-control" placeholder="请输入将要增加的积分数" />
			        	</div>
			        	<div class="form-group">
			        		<label>积分增加事由</label>
			        		<input type="text" name="reason" class="form-control" placeholder="请输入将要增加积分的原因" />
			        	</div>
			        	<input type="hidden" name="id" value="<?php echo $row1['card_id']; ?>">
			        	<input type="hidden" name="tel" value="<?php echo $user_tel; ?>">

			        	<div class="form-group">
			        		<input type="reset" class="btn btn-primary" />
			        		<input type="submit" class="btn btn-danger" />
			        	</div>
			        </form>
			      </div>
			      <div class="modal-footer">
			        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			      </div>
			    </div>
			  </div>
			</div>
			<!-- 扣除积分部分结束 -->
	</div>
</div>
<!-- 右侧内容块结束 -->
<?php
	}else{
		echo "<h1>没有找到该会员</h1>";
	}
}
}

?>
 <?php 
include "../public/footer.php";
 ?>